<template>
	<view>
		<page-head :title="title"></page-head>
		<view class="uni-padding-wrap uni-common-mt">
			<button @tap="doInitSdk">初始化SDK</button>
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<button @tap="doLogin">登录SDK   </button>
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<button @tap="doSetDeviceInfo">设置设备信息</button>
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<button @tap="doEnterAi">进入SDK</button>
		</view>
	</view>
</template>

<script lang="ts">
	import {
		getUniSevenblockAiSdk,
		InitCallback,
		PaymentCallback,
		ControlCommandCallback,
		ConsumeRequestParams,
		RechargeRequestParams,
		ChatTokenConsumeRequestParams,
	} from "@/uni_modules/sevenblock-ai-sdk";
	export default {
		data() {
			return {
				title: "七块AI SDK Demo",
				sdk: getUniSevenblockAiSdk()
			}
		}, 
		methods: {
			doInitSdk: function() {
				const initCallback : InitCallback = {
				 	onInitResult: function(success : boolean, message: string) : void {
				 		console.log("app onInitResult success " + success + " message:" + message)
				 	},
				 	onLoginResult: function(success : boolean, message: string) : void {
				 		console.log("app onLoginResult success " + success + " message:" + message)
				 	}
				 };
				 const paymentCallback : PaymentCallback = {
				 	onConsumeRequest : function(param : ConsumeRequestParams) : void {
				 		console.log("app onConsumeRequest param " + param)
				 	},
				 	onRechargeRequest : function(param : RechargeRequestParams) : void  {
				 		console.log("app onRechargeRequest param " + param)
				 	}, 
				 	onChatTokenConsumeRequest : function(param : ChatTokenConsumeRequestParams) : void {
				 		console.log("app onChatTokenConsumeRequest param  " + param)
				 	}
				 };
				 const toyControllBack : ControlCommandCallback = {
				 	  onControlCmd : function(cmd : string) :void {
				 		  console.log("app onControlCmd:" + cmd)
				 	  },
				 	  requestConnectDevice : function() : void {
				 		  console.log("app requestConnectDevice")
				 	  }
				 };
				 this.sdk.initSdk("sevenblock", initCallback, paymentCallback, toyControllBack)
			},
			doLogin : function() {
				this.sdk.login("17878225071", "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2ZGYxM2UzNTJmNmU0MjcxOTEwZDllMGM5NTVjMzNhOSIsInN1YiI6IntcImFwcElkXCI6XCJzZXZlbmJsb2NrXCIsXCJhdmF0YXJcIjpcImh0dHBzOi8vd3d3LmpveXNkay5hdmF0YXIvam9obnd1LnBuZ1wiLFwiY2hhbm5lbFwiOlwic2V2ZW5ibG9ja1wiLFwiZ2VuZGVyXCI6MixcIm5hbWVcIjpcImpvaG53dVwiLFwidXNlcklkXCI6XCIxNzg3ODIyNTA3MVwifSIsImlzcyI6InNldmVuYmxvY2siLCJpYXQiOjE3NjE3MzI5ODgsImV4cCI6MTc2MTgxOTM4OH0.iobAAroiCP1wyZov8pi5xX3vTE1j9DMZHFnVZXudfVA")
			},
			doSetDeviceInfo : function() { 
				let deviceInfo = {
					deviceName : "S710",
					isAdvertising: true,
					motorType: [0]
				}
				this.sdk.setDeviceInfo(deviceInfo)
			},
			doEnterAi : function() {
				this.sdk.enterAi()
			}
		}
	}
</script>

<style>

</style>
